package com.qky.controller.userController;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.qky.model.user.User;
import com.qky.service.baseService.BaseService;

@Controller
@SessionAttributes("user") 
public class LoginControoller{
	@Resource
	private BaseService<User> uBaseService;
	
	/**
	 * 访问登陆页面的controller,返回登陆页面
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String loginGet() {
		return "user/login";
	}
	
	/**
	 * 点击登录按钮访问的controller，返回登录成功页面 success
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String loginPost(ModelMap map,User user,HttpServletRequest request) {
		try {
			user=uBaseService.getUserByLogin(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		map.put("user",user);
		return "user/success";
	}
	
	/**
	 * 访问首页;
	 * @param map
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String indexGet(ModelMap map,HttpServletRequest request) {
		return "user/success";
	}
}
